<?php
//这是用户操作模块

class main extends spController
{
	function __construct(){ // 公用
		parent::__construct(); // 这是必须的
		$this->tpl_title = "用户模块|主题部分";
	}
	
	function index(){ // 这里是首页
		$this->contents = "用户模块首页内容";
		$this->display("member/main_index.html");
	}
	//添加网站	
	function addsite()
	{
		$this->contents = "添加网站";
		$user = spClass('user');
		$this->value=$user->u_status();
		//$this->ssdd = $_SESSION["userinfo"]["acl"];
		$this->display("member/main_add.html");
	}
	function insert() 
	{
		$data = $this->spArgs ();
		$site = spClass ( 'site' );
		// 使用spVerifier进行一次检查
		$rows = array 
		(
			'domain' => $data ['domain'], 
			'title' => $data ['title'] 
		);
		$results = $site->spVerifier ( $rows );
		if (false == $results) 
		{
			if($site->insert ( $data ))
			{
				$this->success('添加成功',spUrl("main","addsite"));
			}
		} else 
		{
			foreach ( $results as $item ) 
			{
				foreach ( $item as $msg ) 
				{
					$this->error ( $msg, spUrl ( "main", "addsite" ) );
				}
			}
		}
	}
	

	
	function site()
	{
		
		//视图统计
		$record = spClass('record');
		$this->fault=$record->c_fault();
		$this->normal=$record->c_normal();
		//当前用户网站
		$site=spClass('site');
		$this->list=$site->a_site();
		$this->display("member/main_site.html");
	}
	
	function detection()
	{
		$site=spClass('site');
		$this->list=$site->a_site();
		$this->display("member/main_detection.html");
	}
	
	function edit()
	{
		$site=spClass('site');		
		$this->list=$site->a_site();
		$this->display("member/main_edit.html");
	}
	
	function edit_update()
	{		
		$data = $this->spArgs(); 
		$Model = spClass('site');
		
		$Model->create();
		$data['userid']=$_SESSION["userinfo"]["userid"];
		$data['groupid']='1';
        $data['addtime']=strtotime(date("Y-m-d H:i:s"));
        $data['lasttime']=strtotime(date("Y-m-d H:i:s"));
        //数据校验
			$rows = array
			(
				'domain' => $data['domain'], 
				'title' => $data['title']
			);
			$results = $Model->spVerifier($rows);
		if (false == $results)
		{
			$where ['siteid'] = $this->spArgs ( 'siteid' );
			if ($Model->update ( $where, $data )) 
			{
				$this->success('修改成功',spUrl("main","edit"));
				echo $where ['siteid'];
			} 
		}
		else
		{
			foreach($results as $item)
			{
				foreach($item as $msg)
				{ 
					$this->error($msg,spUrl("main","edit"));
				}
			}
		 }

	}
	function del_site()
	{
		$date=$this->spArgs();
		$site = spClass('site');
		dump($date);
		$condition = array
		(
			'siteid'=>$date['siteid']
		);
		dump($condition);
		if($site->delete($condition))
		{
			$this->success('删除成功',spUrl("main","edit"));
		}
	}
	function record()
	{
		$siteid = $this->spArgs('siteid');
		$web_title = $this->spArgs("title");
		$web_domain = $this->spArgs("domain");
		$_SESSION['siteid'] = $siteid;
		$_SESSION['title'] = $web_title;
		$_SESSION['domain'] = $web_domain;
		
		$conditions['siteid'] = $siteid;		
		$record = spClass('record');	
//		$this->results = $record->spPager($this->spArgs('page', 1), 10)->findAll($conditions);
		$this->results = $record->spPager($this->spArgs('page', 1), 10)->findSql("select * from baomu_record where status_code<>200 and siteid = '$siteid'");
		$this->pager = $record->spPager()->getPager();
		
		$this->keyword=$siteid;
		$this->siteid=$siteid;
		$this->web_title=$web_title;
		$this->web_domain = $web_domain;
		
		$this->contents = "网站检测记录详情";
		$this->display("member/main_record.html");
		
	}
	
	function nrecord()
	{	
		$siteid = $this->spArgs('keyword');
		$web_title = $this->spArgs("title");
		$web_domain = $this->spArgs("domain");
		
		$conditions['siteid'] = $siteid;						
		$record = spClass('record');
//		$this->results = $record->spPager($this->spArgs('page', 1), 10)->findAll($conditions);
		$this->results = $record->spPager($this->spArgs('page', 1), 10)->findSql("select * from baomu_record where status_code<>200 and siteid = '$siteid'");
		$this->pager = $record->spPager()->getPager();		

		$this->keyword=$siteid;
		$this->web_title=$_SESSION['title'];
		$this->web_domain = $_SESSION['domain'];
		$this->contents = "网站检测记录详情";
		$this->display("member/main_record.html");		
	}
	
	function ping_site()
	{
		$site = spClass('site');
		$conditions = array
		(
			'p_inter'=>1,
		);
		$sst = $site->findAll($conditions);
		$this->list=$sst;
		$this->display("member/main_detection.html");		
	}
	
	function ping()
	{
		$ping = spClass('ping');
		$this->results = $record->spPager($this->spArgs('page', 1), 10)->findAll($conditions);
		$this->pager = $record->spPager()->getPager();		

		$this->keyword=$siteid;
		$this->web_title=$_SESSION['title'];
		$this->web_domain = $_SESSION['domain'];
		$this->contents = "网站检测记录详情";
		$this->display("member/main_record.html");
	}

	function alarm()
	{
		$this->display("member/main_alarm.html");
	}
	
	function v_group()
	{
		$group = spClass('group');
		print_r($group->s_group());
	}
	
	function sendmail() {
		import("mail/class.phpmailer.php");
		
		$mail = new PHPMailer ();
		
		$mail->IsSMTP (); // 启用SMTP
		$mail->Host = "smtp.163.com"; //SMTP服务器
		$mail->SMTPAuth = true; //开启SMTP认证
		$mail->Username = "lhlb121@163.com"; // SMTP用户名
		$mail->Password = "121956293"; // SMTP密码
		

		$mail->From = "lhlb121@163.com"; //发件人地址
		$mail->FromName = "Mailer"; //发件人
		$mail->AddAddress ( "516000083@qq.com", "Josh Adams" ); //添加收件人
		$mail->AddAddress ( "516000083@qq.com" );
		$mail->AddReplyTo ( "516000083@qq.com", "Information" ); //回复地址
		$mail->WordWrap = 50; //设置每行字符长度
		/** 附件设置
		$mail->AddAttachment("/var/tmp/file.tar.gz");		// 添加附件
		$mail->AddAttachment("/tmp/image.jpg", "new.jpg");	// 添加附件,并指定名称
		 */
		$mail->IsHTML ( true ); // 是否HTML格式邮件
		

		$mail->Subject = "Here is the subject"; //邮件主题
		$mail->Body = "This is the HTML message body <b>in bold!</b>"; //邮件内容
		$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //邮件正文不支持HTML的备用显示
		

		if (! $mail->Send ()) {
			echo "Message could not be sent. <p>";
			echo "Mailer Error: " . $mail->ErrorInfo;
			exit ();
		}
		
		echo "Message has been sent";
	}	
}	